﻿namespace ScrumLite.Services
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Transactions;
    using System.Linq;
    using Contracts;

    public class LinqPeopleService : IPeopleService
    {
        ScrumLite.Data.IUserStore store;

        public LinqPeopleService(ScrumLite.Data.IUserStore store)
        {
            this.store = store;
        }

        public LinqPeopleService()
            : this(new ScrumLite.Data.UserStore())
        {
        }

        public Education[] GetPersonEducation(string personId)
        {
            ScrumLite.Data.Education[] userEducation =  store.RetrieveUserEducation(personId);

            List<Education> personEducation = new List<Education>();

            foreach (ScrumLite.Data.Education education in userEducation)
            {
                personEducation.Add(new Education
                                        { Id = education.id, 
                                          PersonId = education.samAccountName,
                                          Title = education.title,
                                          Certifier = education.certificator,
                                          Completed = education.completed
                                        });
            }

            return personEducation.ToArray();
        }

        public Ability[] GetPersonAbilities(string personId)
        {
            ScrumLite.Data.Ability[] abilities = store.RetrieveUserAbilities(personId);

            List<Ability> personAbilities = new List<Ability>();

            foreach (ScrumLite.Data.Ability ability in abilities)
            {
                personAbilities.Add(new Ability { Id = ability.id, Name = ability.name });
            }

            return personAbilities.ToArray();
        }
    }
}
